import { createRouter, createWebHistory } from 'vue-router'
//import { useUserStore, usePurchaserStore, useSalespersonStore } from '@/stores/index'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: '/login',
      component: () => import('@/views/login/LoginPage.vue')
    },
    {
      path: '/purchaser',
      component: () => import('@/views/purchaser/layout/PurchaserLayout.vue'),
      redirect: '/purchaser/supplierManage',
      children: [
        {
          path: '/purchaser/supplierManage',
          component: () =>
            import('@/views/purchaser/supplierManage/suppliersPage.vue')
        },
        {
          path: '/purchaser/supplierManage/supplierMsg',
          component: () =>
            import(
              '@/views/purchaser/supplierManage/supplierMsg/supplierMsgPage.vue'
            )
        },
        {
          path: '/purchaser/purchaseManage',
          component: () =>
            import('@/views/purchaser/purchaseManage/purchaseOderPage.vue')
        },
        {
          path: '/purchaser/purchaseManage/orderDetails',
          component: () =>
            import(
              '@/views/purchaser/purchaseManage/purchaseOderDetails/purchaseOderDetailsPage.vue'
            )
        },
        {
          path: '/purchaser/purchaseManage/addOrder',
          component: () =>
            import('@/views/purchaser/purchaseManage/addOrder/addOderPage.vue')
        }
      ]
    }
  ]
})

/*router.beforeEach((to) => {
  const userStore = useUserStore()
  const purchaserStore = usePurchaserStore()
  const salespersonStore = useSalespersonStore()

  if (!userStore.token && to.path !== '/login') {
    return '/login'
  } else if (to.path === '/login') {
    userStore.reset()
    purchaserStore.reset()
    salespersonStore.reset()
  }
  else if(to.path.indexOf("/purchaser") === 0 && !purchaserStore.token){
    return '/login'
  }
  else if(to.path.indexOf("/salesperson") === 0 && !salespersonStore.token){
    return '/login'
  }
})*/

export default router
